{extend name="adminblue/base" /}
{block name="resources"/}
<script src="ADMIN_JS/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt>赠品名称:</dt>
		<dd><input type="text" id="gift_name" maxlength="10" class="input-common"></dd>
	</dl>
	<dl>
		<dt>赠品有效期:</dt>
		<dd>
			<input class="input-medium input-common" type="text" id="start_time" style="width:250px;"onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
			<span class="mlr5">-</span> 
			<input class="input-medium input-common" size="15"type="text" id="end_time" style="width:250px;"onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
		</dd>
	</dl>
	<dl>
		<dt>领取有效期:</dt>
			<dd><input class="input-mini w70 input-common" type="text" id="days"><span class="help-inline">天</span></dd>
	</dl>
	<dl>
		<dt>领取限制:</dt>
		<dd>
			<input class="input-mini w70 input-common" type="text" id="max_num"><span class="help-inline">次/人</span>
			<p class="hint">（0表示不限领取次数）</p>
		</dd>
	</dl>
	{include file="adminblue/Promotion/selectGoods" /}
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="addGift();">提交</button></dd>
	</dl>
</div>

<script>
$(function(){
	$('.type_dl dd').hide();
	$("#some_pro").show();
	LoadingInfo();
});

function addGift(){
	var gift_name = $("#gift_name").val();
	var start_time = $("#start_time").val();
	var end_time = $("#end_time").val();
	var days = $("#days").val();
	var max_num = $("#max_num").val();
	var obj = $(".select-two table input[type=checkbox][name='sub']");
	var goods_id_array = '';
	obj.each(function(i){
		goods_id_array += ','+obj.eq(i).val();
	});
	goods_id_array = goods_id_array.substring(1);
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/promotion/addgift')}",
		data : {
			'gift_name' : gift_name,
			'start_time' : start_time,
			'end_time' : end_time,
			'days' : days,
			'max_num' : max_num,
			'goods_id_array' : goods_id_array,
		},
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"],"{:__URL('ADMIN_MAIN/promotion/giftlist')}");
			}else{
				showMessage('error', data["message"]);
			}
		}
	});
}
</script>
{/block}